"""
 -*- coding: utf-8-*-
 @File: api_login.py
 @Author: chen
 @time: 2023/12/01/ 20:40
"""
import os.path

from stage_L1.lim_project.api_po.businesses.api_base import BaseApi
from stage_L1.lim_project.api_po.utils.mgt_yaml import YamlMgt

cur_path = os.path.dirname(os.path.abspath(__file__))
login_file = os.path.join(cur_path, "./config/login_info.yaml")
login_data = YamlMgt.read(login_file)


class LoginApi(BaseApi):
    def login(self):
        """
        登录接口，设置authorization
        :return:
        """

        path = "/user/login"
        data = login_data
        # data = None
        self.payload = {"body": data}
        # 调用登录接口
        resp = self.send("POST", path, json=data)
        res_body = resp.json()
        # 设置authorization
        # Token 42418399e5a70df553f6189ee0a7
        token = res_body["results"]["token"]
        authorization = f"Token {token}"
        self.headers["Authorization"] = authorization
        # print(self._host)


if __name__ == '__main__':
    LoginApi().login()
